package com.umgsai.thread.thread01;

public class MyThread17 extends Thread {

	synchronized public void print(){
		System.out.println("begin...");
		if (Thread.currentThread().getName().equals("a")) {
			System.out.println("a thread suspended forever...");
			Thread.currentThread().suspend();
		}
		System.out.println("end");
	}
	
	public static void main(String[] args) {
		try {
			final MyThread17 thread = new MyThread17();
			Thread t1 = new Thread(){
				@Override
				public void run() {
					thread.print();
				};
			};
			t1.setName("a");
			t1.start();
			Thread.sleep(1000);
			Thread t2 = new Thread(){
				@Override
				public void run() {
					System.out.println("t2启动了，但无法进入print方法..");
					thread.print();
				}
			};
			t2.start();
//			t1.resume();//如果不恢复t1，则t2无法进入print方法
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
